﻿using System.Linq;
using Buddy.BehaviorTree;
using Buddy.CommonBot;
using Buddy.Swtor;
using Buddy.Swtor.Objects;
using WingIt.Dynamics;

namespace WingIt.Routines
{
    public static class JediShadow
    {
        [Class(CharacterClass.Consular, AdvancedClass.Shadow, SkillTreeId.None)]
        [Behavior(BehaviorType.Combat)]
        public static Composite JediShadowCombat()
        {
            return new PrioritySelector(
                //Tank - Requested by Kick.
                /*
                 * Deflection (it's like pally tank 50% tank bubble.  use for a lot of mobs or low hp or something)
Force Breach (instant usable for when we have up to 5 mobs near us... great for if we have 3+ targets w/in .4f)
                 */
                Spell.BuffSelf("Kinetic Ward", ret => !BuddyTor.Me.HasBuff("Kinetic Ward")),
                Spell.BuffSelf("Deflection", ret => BuddyTor.Me.HealthPercent <= 50),
                Spell.Cast("Force Breach", ret => Helpers.Targets.Count(t => t.Distance <= .4f) >= 3),
                
                // 4 yards melee range
                Movement.StopInRange(4f/10f),

                // If we're casting, wait for the cast to finish.
                Spell.WaitForCast(),

                Spell.Cast("Mind Snap", ret => BuddyTor.Me.CurrentTarget.IsCasting),
                Spell.Cast("Spinning Strike"),
                Spell.Cast("Project"),
                Spell.Cast("Telekinetic Throw", ret => BuddyTor.Me.CurrentTarget.Range <= .4f),

				/* 
                Spell.Cast("Force Lift", onUnit =>
                                             {
                                                 var previousTarget = BuddyTor.Me.CurrentTarget;
                                                 return
                                                     Helpers.Targets.FirstOrDefault(
                                                         t =>
                                                         t != previousTarget && (t.Toughness == CombatToughness.Strong)) ??
                                                     Helpers.Targets.FirstOrDefault(t => t != previousTarget);
                                             }, castWhen => Helpers.Targets.Count() >= 3),
				*/

                Spell.BuffSelf("Force Potency", castWhen => Helpers.Targets.Count() >= 5),

                Spell.Cast("Force Stun", castWhen => BuddyTor.Me.CurrentTarget.Toughness == CombatToughness.Strong),

                Spell.Cast("Force Wave", castWhen => Helpers.Targets.Count(t => t.Distance <= .4f) >= 2),

                // Cast these whenever able. Spell.Cast checks for range requirements automatically, so there's no need to add them.
                Spell.Cast("Force Breach", castWhen => BuddyTor.Me.CurrentTarget.Toughness == CombatToughness.Strong),
				/* Use this if we are behind target
                Spell.Cast("Shadow Strike"),
				*/
                Spell.Cast("Double Strike"),
                Spell.Cast("Saber Strike"),

                // Create movement behaviour.
                Movement.MoveTo(ret => BuddyTor.Me.CurrentTarget.Position, 4f/10f)

            ); // End PrioritySelector
        }
    }
}
